package hashmap.demo03;

import java.util.HashMap;

public class HashMapStudent {

    public static void main(String[] args) {

        //创建学生对象
        Student s1 = new Student("海尔",13);
        Student s2 = new Student("格力",22);
        Student s3 = new Student("小米",43);
        Student s4 = new Student("海尔",13);
        //创建集合对象
        HashMap<Student,String> hashMap = new HashMap<>();

        //添加学生对象
        hashMap.put(s1,"北京");
        hashMap.put(s2,"天津");
        hashMap.put(s3,"上海");
        hashMap.put(s4,"广州");

        //遍历
        hashMap.forEach((key,value)->{
            String name = key.getName();
            int age = key.getAge();
            System.out.println(name +"---"+age+"---"+value);
        });

        System.out.println("0---------------------");
        for (Student key:hashMap.keySet()) {
            System.out.println(key.getName()+"---"+key.getAge()+"---"+hashMap.get(key));

        }

    }
}
